package Bidostar_Case;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

import java.awt.*;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

public class FileUpdate
{
    WebDriver driver = new FirefoxDriver();

    @Test
    public void FileUpdateTest() throws Exception
    {
        driver.manage().window().maximize();
        driver.get("http://www.baidu.com");

        StringSelection sel = new StringSelection("/Users/Dreamslians/Desktop/error.png");

        Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, null);
        System.out.println("selection" + sel);

        driver.findElement(By.xpath("//span[@class='soutu-btn']")).click();

        driver.findElement(By.xpath("//input[@class='upload-pic']")).click();

        Robot robot = new Robot();

        Thread.sleep(1000);

        robot.keyPress(KeyEvent.VK_ENTER);

        robot.keyRelease(KeyEvent.VK_ENTER);

        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_V);

        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.keyRelease(KeyEvent.VK_V);

        robot.keyPress(KeyEvent.VK_ENTER);

        robot.keyRelease(KeyEvent.VK_ENTER);
    }
}
